import React from 'react';
import {
  WebView,
  View,
  TouchableOpacity,
} from 'react-native';

import TComponent from './TComponent';

export default class TWebComponent from TComponent {
  constructor(props) {
    super(props);

    // this.props.webviewStyle WebView控件的style 一般只用到宽高

    this.state.initComplete = false;

    this._webViewRef = null;
  }

  render() {
    <View style = {this.props.style}>
      <WebView
          ref={this._initRef.bind(this)}
          automaticallyAdjustContentInsets={false}
          style={this.props.webviewStyle}
          source={}
          javaScriptEnabled={true}
          allowsInlineMediaPlayback={true}
          domStorageEnabled={true}
          decelerationRate="normal"
          startInLoadingState={true}
          scalesPageToFit={this.state.scalesPageToFit}
          onNavigationStateChange={this._onNavigationStateChange.bind(this)}
        />
    </View>
  }

  _initRef(ref) {
    this._webViewRef = ref;
    this.setState({
      initComplete:true,
    })
  }

  _getSource() {
    if(this.state.initComplete === true) {
      return this.state.source;
    }
    return {uri:""};
  }

  _setUrl(url) {
    this.state.url = url;
    this.state.source = {uri:url};
    this._customUrl = url;
  }
}
